<?php
namespace App\Services\Main;

use App\Repositories\Main\ComContractRepository;

class ComContractService
{
    private $service;

    public function __construct()
    {
        $this->service = new ComContractRepository();
    }

    public function getAdminIndex($baleId=0)
    {
        return $this->service->getAdminIndex($baleId);
    }

    public function setAdd($orderId,$uid,$file)
    {
        $model = $this->service->getOneByBale($orderId);
        if ($model) {
           /* if ($model->file && file_exists(ltrim('/',$model->fie))) {
                unlink(ltrim('/',$model->fie));
            }*/
            $dataArr = array(
                'file' => $file,
            );
            $this->service->setModify($dataArr,$orderId);
            return $model->id;
        } else {
            $dataArr = array(
                'bale' => $orderId,
                'cid' => $uid,
                'file' => $file,
            );

            return $this->service->setAdd($dataArr);
        }
    }

    public function getOne($id)
    {
        return $this->service->getShowOne($id);
    }
}